<template>
	<view>
		<view class="goods-item" >
			<!-- 商品图片 -->
			<view class="goods-item-left">
				<!-- 商品选中状态 -->
				<radio  :checked="goods.goods_state" color="#c00000" v-if="showRadio" @click="radioClickHandler"/>
				<image :src="goods.goods_small_logo || defaultPic" class="goods-pic"></image>
			</view>
			<!-- 文字信息 -->
			<view class="goods-item-right">
				<view class="goods-title">{{goods.goods_name}}</view>
				<view class="goods-info-box">
					<!-- 商品价格 -->
					<view class="goods-price">￥{{goods.goods_price | tofixed}}</view>
					<!-- 商品数量 -->
					<uni-number-box :min="1" :value="goods.goods_count" v-if="showNum" @change="numChangeHandler"></uni-number-box>
				</view>
				
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		name: "my-goods",
		data() {
			return {
				// 默认图片
				defaultPic: 'https://cn.bing.com/images/search?view=detailV2&ccid=6Yw261V7&id=4F92EAC20C9E25C2790E5F40DEF5F1625FEE8438&thid=OIP.6Yw261V7xODwwK-Etsse7gHaHo&mediaurl=https%3a%2f%2fts1.cn.mm.bing.net%2fth%2fid%2fR-C.e98c36eb557bc4e0f0c0af84b6cb1eee%3frik%3dOITuX2Lx9d5AXw%26riu%3dhttp%253a%252f%252fstatic.managershare.com%252fuploads%252f2017%252f07%252fa370e_2ed40004d66ad7d951a2.jpg%26ehk%3d24q%252bwuXBmldceM6fYuB7Hic7qb6zDJW3Rw66qdqmci4%253d%26risl%3d%26pid%3dImgRaw%26r%3d0&exph=660&expw=640&q=%e7%8c%ab%e5%92%aa%e8%a1%a8%e6%83%85%e5%8c%85&simid=608046964531282729&FORM=IRPRST&ck=EC777BDEDFEDE08AD8B38F5AA4CCFB71&selectedIndex=33&ajaxhist=0&ajaxserp=0'		
			};
		},
		props:{
			// 商品信息对象
			goods:{
				type:Object,
				default:{}
			},
			// 是否展示勾选图标
			showRadio:{
				type:Boolean,
				default:false
			},
			// 是否展示数量框
			showNum:{
				type:Boolean,
				default:false
			}
		},
		filters:{
			tofixed(num){
				return Number(num).toFixed(2)
				
			}
		},
		methods:{
			// 商品选框
			radioClickHandler(){
				this.$emit('radio-change',{
					 goods_id:this.goods.goods_id,
					 goods_state:!this.goods.goods_state,
				})		
			},
			// 商品数量框
			numChangeHandler(val){
				this.$emit('num-change',{
					goods_id:this.goods.goods_id,
					goods_count:+val
				})
			}
		
		}
		
	}
</script>

<style lang="scss">
	.goods-item {
		width: 750rpx;
		box-sizing: border-box;
		display: flex;
		padding: 10px 5px;
		border-bottom: 1px solid #f0f0f0;

		.goods-item-left {
			margin-right: 5px;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.goods-pic {
				width: 100px;
				height: 100px;
				display: block;

			}
		}

		.goods-item-right {
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.goods-title {
				font-size: 13px;

			}

			.goods-info-box{
				display: flex;
				justify-content: space-between;
				
				.goods-price {
					color: #c00000;
					font-size: 16px;
				}
				
			}
			
			
		}

	}
</style>
